﻿using System;
using System.Collections.Generic;
using System.Text;

namespace Vortex.Drawing {

	/// <summary>
	/// Class which contains information about 2D scaling against the origin point
	/// </summary>
	public class Scaling : ITransform {
		private Vector2 _origin;
		private Vector2 _factor;

		/// <summary>
		/// Initializes a new instance of the <see cref="Scaling"/> class.
		/// </summary>
		/// <param name="factor">The scaling factor.</param>
		public Scaling(float factor) {
			_factor = new Vector2(factor);
			_origin = Vector2.Zero;
		}

		/// <summary>
		/// Initializes a new instance of the <see cref="Scaling"/> class.
		/// </summary>
		/// <param name="factor">The scaling factor.</param>
		/// <param name="origin">The scaling origin point.</param>
		public Scaling(Vector2 factor) {
			_factor = factor;
			_origin = Vector2.Zero;
		}

		/// <summary>
		/// Initializes a new instance of the <see cref="Scaling"/> class.
		/// </summary>
		/// <param name="factor">The scaling factor.</param>
		/// <param name="origin">The scaling origin point.</param>
		public Scaling(float factor, Vector2 origin) {
			_factor = new Vector2(factor);
			_origin = origin;
		}

		/// <summary>
		/// Initializes a new instance of the <see cref="Scaling"/> class.
		/// </summary>
		/// <param name="factor">The scaling factor.</param>
		/// <param name="originX">The scale origin X coord.</param>
		/// <param name="originY">The scale origin Y coord.</param>
		public Scaling(float factor, float originX, float originY) {
			_factor = new Vector2(factor);
			_origin = new Vector2(originX, originY);
		}

		/// <summary>
		/// Initializes a new instance of the <see cref="Scaling"/> class.
		/// </summary>
		/// <param name="factorX">The scaling factor X.</param>
		/// <param name="factorY">The scaling factor Y.</param>
		/// <param name="originX">The scale origin X coord.</param>
		/// <param name="originY">The scale origin Y coord.</param>
		public Scaling(float factorX, float factorY, float originX, float originY) {
			_factor = new Vector2(factorX, factorY);
			_origin = new Vector2(originX, originY);
		}

		/// <summary>
		/// Initializes a new instance of the <see cref="Scaling"/> class.
		/// </summary>
		/// <param name="factor">The scaling factor.</param>
		/// <param name="origin">The scaling origin point.</param>
		public Scaling(Vector2 factor, Vector2 origin) {
			_factor = factor;
			_origin = origin;
		}

		/// <summary>
		/// Gets or sets the scaling factor.
		/// </summary>
		/// <value>The scaling factor.</value>
		public Vector2 Factor {
			get { return _factor; }
			set { _factor = value; }
		}

		/// <summary>
		/// Gets or sets the scaling factor X.
		/// </summary>
		/// <value>The scaling factor X.</value>
		public float FactorX {
			get { return _origin.X; }
			set { _origin.X = value; }
		}

		/// <summary>
		/// Gets or sets the scaling factor Y.
		/// </summary>
		/// <value>The scaling factor Y.</value>
		public float FactorY {
			get { return _origin.Y; }
			set { _origin.Y = value; }
		}

		/// <summary>
		/// Gets or sets the scaling origin.
		/// </summary>
		/// <value>The scaling origin.</value>
		public Vector2 Origin {
			get { return _origin; }
			set { _origin = value; }
		}

		/// <summary>
		/// Gets or sets the X coordinate of origin.
		/// </summary>
		/// <value>The X origin coord.</value>
		public float OriginX {
			get { return _origin.X; }
			set { _origin.X = value; }
		}

		/// <summary>
		/// Gets or sets the Y coordinate of origin.
		/// </summary>
		/// <value>The Y origin coord.</value>
		public float OriginY {
			get { return _origin.Y; }
			set { _origin.Y = value; }
		}

		/// <summary>
		/// Empty scale value
		/// </summary>
		/// <value>The empty scale.</value>
		public static Scaling Empty {
			get { return new Scaling(1); }
		}	

		#region ITransform Members

		/// <summary>
		/// Gets the transform which represents this scaling.
		/// </summary>
		/// <param name="transform">The transform represented by this scaling.</param>
		public void GetTransform(out Transform2D transform) {
			Transform2D.CreateScaling(ref _factor, ref _origin, out transform);
		}

		#endregion
	}
}
